import {defineConfig, loadEnv} from "vite";
import createVitePlugins from "./vite/plugins";
import {resolve} from "path";

export default defineConfig(({mode, command}) => {
    const env = loadEnv(mode, process.cwd());
    return {
        build: {
            commonjsOptions: {
                transformMixedEsModules: true,
                include: [],
            },
        },
        server: {
            port: 8082,
            proxy: {
                "/api": {
                    target: "http://localhost:13800",
                    changeOrigin: true,
                    rewrite: (path) => path.replace(/^\/api/, ""),
                },
            },
        },
        resolve: {
            alias: {
                "@": resolve(__dirname, "./src"),
                components: resolve(__dirname, "./src/components"),
                styles: resolve(__dirname, "./src/styles"),
                utils: resolve(__dirname, "./src/utils"),
            },
        },
        plugins: createVitePlugins(env, command === "build"),
    };
});
